<template>
  <div class="select-tree">
<!--    <div class="flex_content_sp">-->
<!--      <el-input placeholder="输入关键字进行过滤" v-model="input3"> </el-input>-->
<!--      <el-button type="primary" size="mini" @click="handleSearch"-->
<!--        >搜索</el-button-->
<!--      >-->
<!--    </div>-->

    <el-tree
      class="filter-tree"
      :data="data"
      node-key="id"
      :props="defaultProps"
      :default-checked-keys="[1]"
      :default-expanded-keys="['0-0-0']"
      :filter-node-method="filterNode"
      @node-click="handleClick"
      ref="tree"
    >
    </el-tree>
  </div>
</template>

<script>
import {api, option} from '@/utils/file'
export default {
  name: "index",
  props: {
    optionType: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      input3: "",
      data: [],
      defaultProps: {
        children: "children",
        label: "name",
      },
    };
  },
  created() {
    if(this.optionType==='option'){
      this.data = option
    }else if(this.optionType === 'api'){
      this.data = api

    }else if(this.optionType==='gloption'){

    }
  },
  inject:['handleSwitchItem'],
  methods: {
    handleClick(e){
      console.log(e,'eee')
      if(e.level===1){
        this.handleSwitchItem(e.id)
      }
    },
    handleSearch() {
      this.$refs.tree.filter(this.input3);
    },
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
  },
};
</script>

<style scoped></style>
